const jwt = require('../utils/jwt')
const secret = 'b746aa49-e84d-4bac-b262-2f2f58faa174'


exports.login = async (req, res, next) => {
  try {
    const { username, password } = req.body
    if (username == 'admin' && password == 'qwe123') {
      const token = await jwt.sign({username, password }, secret, { expiresIn: 30 * 60 })
      return res.status(200).json({msg: '', data: token})
    } else {
      return res.status(200).json({
        msg: '用户名、密码错误'
      })
    }
  } catch (error) {
    next(error)
  }
}

exports.showIndex = (req, res, next) => {
  try {
    res.render('login')
  } catch (error) {
    next(error)
  }
}